#include <openpcg/openpcg.h>
#include <stdio.h>

double fact(int f) {
	if (f == 0) return 1;
	return fact(f - 1) * f;
}

double fact_handler(pcg_exprlist_t *el) {
	return fact((int) el->head->lval.dval);
}

int main(int argc, char *argv[]) {
	pcg_expr_t *my_expr;
	double result;
	pcg_runtime_t *rt = pcg_runtime_create();
	
	pcg_runtime_add_symbol(rt, "factorial", 1, fact_handler);
	
	my_expr = pcg_runtime_expr_from_string(rt, "4 + factorial(5)");
	result = pcg_runtime_eval_expr(rt, my_expr);
	
	printf("%.2f\n", result);
	
	pcg_runtime_delete(rt);
}
